package com.gf.forcesystem.scene;

import com.gf.forcesystem.model.dto.BaseUnit;
import com.gf.forcesystem.model.dto.weather.AbstractWeather;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author gaofei
 * @date 2022/6/20 22:05
 * 场景信息
 */
public class SceneInfo {
    /**
     * 单位信息
     */
    private final Map<String, BaseUnit> unitMap = new HashMap<>();
    /**
     * 天气信息
     */
    private final Map<Class<?>, AbstractWeather> weatherMap = new HashMap<>();

    /**
     * 重置场景
     */
    public synchronized void clear() {
        unitMap.clear();
        weatherMap.clear();
    }

    public synchronized void setWeather(Class<?> dataType, AbstractWeather weath) {
        weatherMap.put(dataType, weath);
    }

    /**
     * 获取天气列表
     * @return
     */
    public synchronized List<AbstractWeather> weatherList() {
        return new ArrayList<>(weatherMap.values());
    }

    /**
     * 添加单位
     * @param id
     * @param baseUnit
     */
    public synchronized void addUnit(String id, BaseUnit baseUnit) {
        unitMap.put(id, baseUnit);
    }

    /**
     * 删除单位
     * @param id
     */
    public synchronized void delUnit(String id) {
        unitMap.remove(id);
    }

    /**
     * 获取单位列表
     * @return
     */
    public synchronized List<BaseUnit> unitList() {
        return new ArrayList<>(unitMap.values());
    }

    /**
     * 获取单位list
     * @return
     */
    public synchronized Map<String, BaseUnit> getUnitMap() {
        return new HashMap<>(unitMap);
    }
}
